<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    html {
      height: 5000px;
    }
  </style>
</head>

<body>
  <input type="text" id="input" value="123">
  <script>
    const Input = document.querySelector("#input");
    let fn1 = function (name) {
      console.log(this, this.value);
      // console.log(name);
    };
    //   传12参数
    Input.oninput = debounce(fn1, 1000, 12);
    //   接收参数
    function debounce(fn, delay, immediate = true, ...arg) {
      let timer = null;
      // if (immediate) {
      //   fn.apply(Input)
      //   immediate = false;
      // }
      return function () {
        // console.log(this, 'this2');//input
        timer && clearTimeout(timer);
        timer = setTimeout(() => {
          // 参数赋给匿名函数，并且调用带参数
          fn.apply(this, arg);
        }, delay);
      };
    }

    //   节流
    window.onscroll = throttle(function () {
      alert("我是广告");
    }, 2000);
    function throttle(fn, delay) {
      let t = true;
      return function (...arguments) {
        if (t) {
          setTimeout(() => {
            fn.apply(this, arguments);
            t = true;
          }, delay);
        }
        t = false;
      };
    }

    function name(params) {
      console.log(params);
      params = 1

      return function hah() {
        console.log(params);
      }
    }
    name()
  </script>
</body>

</html>